package com.hengxinguotong.zhihuichengjian.ui.environment.data;

import android.os.Bundle;
import android.view.View;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.EnvironmentHistory;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/24
 *
 * 环境监测历史数据详情
 */

public class EnvironmentHistoryDetailActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.title_tv)
    HXTextView titleTv;
    @BindView(R.id.upload_time)
    HXTextView uploadTime;
    @BindView(R.id.pm_10)
    HXTextView pm10;
    @BindView(R.id.pm_25)
    HXTextView pm25;
    @BindView(R.id.noise)
    HXTextView noise;
    @BindView(R.id.temperature)
    HXTextView temperature;
    @BindView(R.id.humidity)
    HXTextView humidity;
    @BindView(R.id.wind_speed)
    HXTextView windSpeed;
    @BindView(R.id.wind_direction)
    HXTextView windDirection;
    @BindView(R.id.current_spray_status)
    HXTextView currentSprayStatus;

    private EnvironmentHistory environmentHistory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_environment_history_detail);
        ButterKnife.bind(this);
        environmentHistory = (EnvironmentHistory) getIntent().getSerializableExtra("environmentHistory");
        initView();
    }

    private void initView() {
        titleTv.setText(R.string.history_data_detail);

        uploadTime.setText(environmentHistory.getTime());
        setmText(pm10, environmentHistory.getPm10() + "微克/立方米", environmentHistory.getPm10Status());//噪音警报状态 0正常 1预警 2报警
        setmText(pm25, environmentHistory.getPm25() + "微克/立方米", environmentHistory.getPm25Status());//噪音警报状态 0正常 1预警 2报警
        setmText(noise, environmentHistory.getNoise() + "分贝", environmentHistory.getNoiseStatus());//噪音警报状态 0正常 1预警 2报警
        setmText(temperature, environmentHistory.getTemperature() + "度", environmentHistory.getTemperatureStatus());//噪音警报状态 0正常 1预警 2报警
        setmText(humidity, environmentHistory.getHumidity() + "%", environmentHistory.getHumidityStatus());//噪音警报状态 0正常 1预警 2报警
        setmText(windSpeed, environmentHistory.getNoise() + "米/秒", environmentHistory.getWindSpeedStatus());//噪音警报状态 0正常 1预警 2报警
        windDirection.setText(environmentHistory.getWindDirection());
        if(environmentHistory.getSprayStatus() == 0){//喷淋状态 0手动 1自动
            currentSprayStatus.setText("手动");
        }else {
            currentSprayStatus.setText("自动");
        }
    }

    @OnClick({R.id.back_tv})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back_tv:
                finish();
                break;
        }
    }

    private void setmText(HXTextView textView, int status){
        switch (status){
            case 0:
                textView.setText(R.string.normal);
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(R.string.warning);
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(R.string.alarm);
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
            case 3:
                textView.setText(R.string.violation);
                textView.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }
    }

    private void setmText(HXTextView textView, String text, int status){
        switch (status){
            case 0:
                textView.setText(text + "（正常）");
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(text + "（预警）");
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(text + "（报警）");
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
            case 3:
                textView.setText(text + "（违章）");
                textView.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }
    }

    private int getmColor(int colorId){
        return getResources().getColor(colorId);
    }

}
